package com.vegetable.modules.controller.finance;

import com.alibaba.fastjson.JSON;
import com.vegetable.common.annotation.SysLog;
import com.vegetable.common.utils.PageUtils;
import com.vegetable.common.utils.R;
import com.vegetable.modules.controller.AbstractController;
import com.vegetable.modules.entity.finance.PaymentTeam;
import com.vegetable.modules.service.finance.IPaymentTeamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 班组付款 前端控制器
 * </p>
 *
 * @author wangruijie
 * @since 2024-04-15
 */
@Slf4j
@RestController
@RequestMapping("/payment/team")
@AllArgsConstructor
@Api(value = "班组付款", tags = "班组付款")
public class PaymentTeamController extends AbstractController {

    private IPaymentTeamService financialService;
    /**
     * 所有班组付款列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "条件查询班组付款列表", notes = "条件查询班组付款列表")
    public R list(@RequestParam Map<String, Object> params){
        // 状态0收款，1付款
        params.put("type", 1);
        log.info("条件查询班组付款列表{}", JSON.toJSONString(params));
        PageUtils page = financialService.queryPage(params);
        return R.data( page);
    }

    /**
     * 新增班组付款
     */
    @SysLog(value = "新增班组付款")
    @PostMapping("/saveTeam")
    @ApiOperation(value = "新增班组付款", notes = "新增班组付款")
    public R saveTeam(@RequestBody PaymentTeam financial) throws Exception {
        log.info("新增班组付款：{}", JSON.toJSONString(financial));
        financial.setCreateUserId(getUserId());
        return financialService.saveTeamPayment(financial);

    }

    /**
     * 删除班组付款
     */
    @SysLog(value = "删除班组付款")
    @GetMapping("/deleteTeam")
    @ApiOperation(value = "根据id删除班组付款", notes = "根据id删除班组付款")
    public R deleteTeam(Long id){
        log.info("删除班组付款：{}", JSON.toJSONString(id));
        try {
            return financialService.deleteTeam(id);
        } catch (Exception e) {
            e.printStackTrace();
            return R.fail(e.getMessage());
        }
    }

}
